package com.guofen.controller.sjq;

import com.guofen.pojo.SjqDeodorizationRunningFour;
import com.guofen.service.sjq.SjqDeodorizationRunningFourService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/sjq/deodorizationRunningFour")
@Controller
@Api(tags = "SjqDeodorizationRunningFourController", description = "除臭记录表4")
public class SjqDeodorizationRunningFourController {

    @Autowired
    private SjqDeodorizationRunningFourService sjqDeodorizationRunningFourService;

    @ApiOperation("添加记录")
    @RequestMapping(value = "/addForm", method = RequestMethod.POST)
    @ResponseBody
    public Result addOperationalForm(@ApiParam(name = "date", value = "日期", required = true) @RequestParam String date,
                                     @ApiParam(name="killRange",value="消杀范围",required=true) @RequestParam String killRange,
                                     @ApiParam(name = "killDrugName", value = "消杀药品名称", required = true) @RequestParam String killDrugName,
                                     @ApiParam(name = "proportioningDegree", value = "配比度", required = true) @RequestParam String proportioningDegree,
                                     @ApiParam(name = "consumption", value = "使用量", required = true) @RequestParam Double consumption){
        if (sjqDeodorizationRunningFourService.addForm(date, killRange, killDrugName, proportioningDegree, consumption))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }


    @ApiOperation("删除记录")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(sjqDeodorizationRunningFourService.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                         @ApiParam(name="killRange",value="消杀范围",required=true) @RequestParam String killRange,
                         @ApiParam(name="killDrugName",value="消杀药品名称",required=true) @RequestParam String killDrugName,
                         @ApiParam(name="proportioningDegree",value="配比度",required=true) @RequestParam String proportioningDegree,
                         @ApiParam(name="consumption",value="使用量",required=true) @RequestParam Double consumption) {
        SjqDeodorizationRunningFour record = new SjqDeodorizationRunningFour();
        record.setId(id);
        record.setKillRange(killRange);
        record.setKillDrugName(killDrugName);
        record.setProportioningDegree(proportioningDegree);
        record.setConsumption(consumption);
        return ResultGenerator.genSuccessResult(sjqDeodorizationRunningFourService.update(record));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(sjqDeodorizationRunningFourService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(sjqDeodorizationRunningFourService.getByTime(pageSize, currentPage, startTime, endTime));
    }
}
